/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kmcsoft.core.service.impl;

import com.kmcsoft.core.service.MasterService;
import com.kmcsoft.demography.entity.Country;
import com.kmcsoft.demography.entity.District;
import com.kmcsoft.demography.entity.Province;
import com.kmcsoft.demography.entity.Ward;
import java.util.Collection;

/**
 *
 * @author phuocthai
 */
public class JdoMasterService extends DefaultGenericService implements MasterService {

    public Collection<Country> getCountries() {
        Collection<Country> countries = getJdoTemplate().find(Country.class);
        return getJdoTemplate().detachCopyAll(countries);
    }

    public Collection<Province> getProvinces(Country country) {
        Collection<Province> provinces = getJdoTemplate().find(Province.class,
                "country == pCountry",
                Country.class.getName() + " pCountry",
                country);
        return getJdoTemplate().detachCopyAll(provinces);
    }

    public Collection<District> getDistricts(Province province) {
        Collection<District> districts = getJdoTemplate().find(District.class,
                "province == pProvince",
                Province.class.getName() + " pProvince",
                province);
        return getJdoTemplate().detachCopyAll(districts);
    }

    public Collection<Ward> getWards(District district) {
        Collection<Ward> wards = getJdoTemplate().find(Ward.class,
                "district == pDistrict",
                District.class.getName() + " pDistrict",
                district);
        return getJdoTemplate().detachCopyAll(wards);
    }
}
